package leetcode.n2021;

/**
 * https://leetcode-cn.com/problems/next-greater-element-i/description/
 * https://leetcode.com/problems/next-greater-element-i/?tab=Description
 * @program: brushing
 * @description:
 * @author: LiuQiang
 * @create: 2018-07-25 10:35
 **/
public class NextGreaterElement {
    public int[] test(int[] findNums, int[] nums) {
        int a[] = new int[findNums.length];

        for (int i = 0; i < findNums.length; i++) {
            int flag = -1;
            for (int j = 0; j < nums.length; j++) {
                if (findNums[i] == nums[j]) {
                    flag = j;
                }
            }

            if (flag == -1 || flag == nums.length - 1) {
                a[i] = -1;
            } else {
                a[i] = -1;
                for (int k = flag; k < nums.length; k++) {
                    if (nums[k] > findNums[i]) {
                        a[i] = nums[k];
                        break;
                    }
                }
            }
        }

        return a;
    }

    public static void main(String[] args) {
        int a[] = {4, 1, 2};
        int b[] = {1, 3, 4, 2};

		/*int a[] = {1,3,5,2,4};
		int b[] = {6,5,4,3,2,1,7};*/

        NextGreaterElement n = new NextGreaterElement();
        int c[] = n.test(a, b);
        for (int i : c) {
            System.out.println(i);
        }
    }
}
